package com.sky.controller.user;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderSubmitVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/user/order")
@RestController("UserOrderController")
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;
    /**
     * 用户提交订单
     * @param ordersSubmitDTO
     * @return
     */
    @PostMapping("/submit")
    public Result<OrderSubmitVO> submit(@RequestBody OrdersSubmitDTO ordersSubmitDTO) {
        log.info("用户提交订单，传递来的参数是{}",ordersSubmitDTO);
        OrderSubmitVO orderSubmitVO =orderService.submit(ordersSubmitDTO);
        return Result.success(orderSubmitVO);
    }

    /**
     * 查询历史订单
     */
    @GetMapping("/historyOrders")
    public Result<PageResult> historyOrders(@ModelAttribute OrdersPageQueryDTO ordersPageQueryDTO) {
        log.info("传递来的参数是{}",ordersPageQueryDTO);
        PageResult search = orderService.UserHistoryOrders(ordersPageQueryDTO);
        return Result.success(search);
    }
    /**
     * 查询用户订单详情
     */
    @GetMapping("/orderDetail/{id}")
    public Result<Orders> orderDetail(@PathVariable Long  id) {
        log.info("要查询的订单的id是{}",id);
        Orders orders = orderService.selectUserOrderDetail(id);
        return Result.success(orders);
    }
    /**
     * 用户取消订单
     */
    @PutMapping("/cancel/{id}")
    public Result cancel(@PathVariable Long id ){
        log.info("订单取消，传递来的参数是{}",id);
        OrdersCancelDTO ordersCancelDTO = new OrdersCancelDTO();
        ordersCancelDTO.setId(id);
        orderService.cancel(ordersCancelDTO);
        return Result.success();
    }
    /**
     * 用户再来一单
     */
    @PostMapping("/repetition/{id}")
    public Result repetition(@PathVariable Long id) {
        log.info("再来一单，传递来的参数是{}",id);
        orderService.repetition(id);
        return Result.success();
    }

    /**
     * 用户催单
     */
    @GetMapping("/reminder/{id}")
    public Result reminder(@PathVariable Long id) {
        log.info("用户催单，传递来的参数是{}",id);
        orderService.reminder(id);
        return Result.success();
    }
}
